package com.ruoyi.system.escontroller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.ByDb15;
import com.ruoyi.system.domain.ByNews;
import com.ruoyi.system.service.IByNewsService;
import com.ruoyi.system.service.IEsService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("es")
@AllArgsConstructor
public class EsController {

    @Autowired
    private IEsService esService;

    /**
     * 创建标准索引
     */
    @GetMapping("/createIndex")
    public AjaxResult createIndex()
    {
        esService.createIndex();
        return  AjaxResult.success();
    }

    /**
     * 创建标准结构化索引
     */
    @GetMapping("/createStructIndex")
    public AjaxResult createStructIndex()
    {
        esService.createStructIndex();
        return  AjaxResult.success();
    }

    /**
     * 获取索引数据总数
     */
    @GetMapping("/searchIndex")
    public AjaxResult searchIndex()
    {
        return  AjaxResult.success(esService.searchIndex());
    }

    /**
     * 删除标准索引
     */
    @GetMapping("/deleteIndex")
    public AjaxResult deleteIndex()
    {
        esService.deleteIndex();
        return  AjaxResult.success();
    }

    /**
     * 删除结构化索引
     */
    @GetMapping("/deleteStructIndex")
    public AjaxResult deleteStructIndex()
    {
        esService.deleteStructIndex();
        return  AjaxResult.success();
    }


    /**
     * 添加索引内容
     */
    @GetMapping("/addContent")
    public AjaxResult addContent(ByDb15 byDb15)
    {
        esService.addContent(byDb15);
        return  AjaxResult.success();
    }

    /**
     * 删除所有索引
     */
    @GetMapping("/deleteIndexDocAll")
    public AjaxResult deleteIndexDocAll(String indexName)
    {
        esService.deleteIndexDocAll(indexName);
        return  AjaxResult.success();
    }

    /**
     * 按id添加文档
     */
    @GetMapping("/deleteIndexDocById")
    public AjaxResult deleteIndexDocById(String indexName)
    {
        esService.deleteIndexDocAll(indexName);
        return  AjaxResult.success();
    }


    /**
     * 根据表名添加索引内容
     */
    @GetMapping("/addContentByTableName")
    public AjaxResult addContentByTableName(String tableName)
    {
        esService.addContentByTableName(tableName);
        return  AjaxResult.success();
    }

    /**
     * 全部表名初始化
     */
    @GetMapping("/addContentByTableNameAll")
    public AjaxResult addContentByTableNameAll()
    {
        esService.addContentByTableNameAll();
        return  AjaxResult.success();
    }

    /**
     * 结构化数据初始化
     */
    @GetMapping("/synStruct")
    public AjaxResult synStruct()
    {
        esService.synStruct();
        return  AjaxResult.success();
    }


    /**
     * 全部发布时间初始化
     */
    @GetMapping("/udpatePubTimeAll")
    public AjaxResult updatePubTimeAll()
    {
        esService.addContentByTableNameAll();
        return  AjaxResult.success();
    }


    /**
     * 全部发布时间初始化
     */
    @GetMapping("/insertNewIndex")
    public AjaxResult insertNewIndex()
    {
        esService.insertNewIndex();
        return  AjaxResult.success();
    }


    /**
     * 全部表名初始化价格
     */
    @GetMapping("/addContentByTableNameAllPrice")
    public AjaxResult addContentByTableNameAllPrice()
    {
        esService.addContentByTableNameAllPrice();
        return  AjaxResult.success();
    }


    /**
     * 添加索引内容
     */
    @GetMapping("/updateFileByTableName")
    public AjaxResult updateFileByTableName(String tableName)
    {
        esService.updateFIlePath(tableName);
        return  AjaxResult.success();
    }


    /**
     * 添加索引内容
     */
    @GetMapping("/updateFileByTableNameBak")
    public AjaxResult updateFileByTableNameBak()
    {
        esService.updateFIlePathByTableName();
        return  AjaxResult.success();
    }


    /**
     * 添加索引内容
     */
    @GetMapping("/search")
    public TableDataInfo search(String keyNum)
    {
        return  esService.search(keyNum);
    }

    /**
     * 添加索引内容
     */
    @GetMapping("/initAllFile")
    public AjaxResult initAllFile()
    {
        return esService.initAllFile();
    }


    /**
     * 添加索引内容
     */
    @GetMapping("/initTableNameFile/{tableName}")
    public AjaxResult initTableNameFile(@PathVariable  String tableName)
    {
        return esService.initTableNameFile(tableName);
    }


    /**
     * 依据表名更新es索引
     */
    @GetMapping("/updateByTableName")
    public AjaxResult updateByTableName(String tableName)
    {
        esService.updateByTableName(tableName);
        return  AjaxResult.success();
    }

}
